package spring.framework.beans.factory.support;

import spring.framework.beans.BeansException;
import spring.framework.beans.factory.config.BeanDefinition;

/**
 * @author fun.pengzh
 * @class spring.framework.beans.factory.support.AbstractAutoWireCapableBeanFactory
 * @desc
 * @since 2021-09-18
 */
public abstract class AbstractAutoWireCapableBeanFactory extends AbstractBeanFactory {

    protected abstract BeanDefinition getBeanDefinition(String beanName);

    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws  BeansException{
        Object object = null;
        try {
            object = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed",e);
        }
        addSingleton(beanName, object);
        return object;
    }

}
